package cn.tedu.order.tcc;

import io.seata.rm.tcc.api.BusinessActionContext;
import io.seata.rm.tcc.api.BusinessActionContextParameter;
import io.seata.rm.tcc.api.LocalTCC;
import io.seata.rm.tcc.api.TwoPhaseBusinessAction;

import java.math.BigDecimal;

/**
 * 订单的tcc接口
 */
@LocalTCC
public interface OrderTccAction {
    //T-预留资源。冻结数据
    //将数据放到上下文对象
    //为了避开seata 的bug 这里不接收封装的订单对象，而是一个个接收订单的数据
    //@BusinessActionContextParameter  将接收的数据填充到context上下问对象中去；
    @TwoPhaseBusinessAction(name = "OrderTccAction",commitMethod = "commit",rollbackMethod = "rollback")
    boolean prepare( BusinessActionContext ctx,
                     @BusinessActionContextParameter(paramName = "orderId")Long orderId,
                     @BusinessActionContextParameter(paramName = "userId")Long userId,
                     @BusinessActionContextParameter(paramName = "productId")Long productId,
                     @BusinessActionContextParameter(paramName = "count")Integer count,
                     @BusinessActionContextParameter(paramName = "money")BigDecimal money);
    //c-confirm 确认 提交
    boolean commit(BusinessActionContext ctx);
    //c-取消 回滚
    boolean rollback(BusinessActionContext ctx);
}
